<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<title>Excel导出</title>
<style type="text/css">
.button_orange {
	height: 25px;
	font-size: 12px;
	color: #cc3300;
	border: 1px #cc9933 solid;
	background: url(${res}/images/button_orange.gif);
	padding: 0 15px;
	*padding: 0 10px;
	_padding: 0 10px;
	cursor: pointer;
}
</style>
</head>
<body>
	<input type="hidden" id="childDiv" class="thickbox" />
	<form method="post" id="mainForm">
		<input type="hidden" id="prpCodes" name="prpCodes" value="" /> <input
			type="hidden" id="type" name="type" value="" />
	</form>
	<br />
	<div class="soBox">
		<div class="detail ico_search">
			<table>
				<tr>
					<td rowspan="2"><strong>检索条件：</strong></td>
					<security:authorize ifNotGranted="A_AUTH_DW">
						<td><cpt:search key="prpApprove_search22_chushi" repeatColumn="3" displayCount="5" leftStyle="width:100px"></cpt:search>
						</td>
					</security:authorize>
					<security:authorize ifAnyGranted="A_AUTH_DW">
						<td><cpt:search key="prpApprove_search22" repeatColumn="3" displayCount="5" leftStyle="width:100px"></cpt:search></td>
					</security:authorize>
				</tr>

				<tr>
					<td>
						<div class="clear_h10"></div> <input type="hidden" id="limitinfo" name="limitinfo" value="" />
						 <input type='button' id='searchBt' class="button_an" value='查询' /> 
						<input type='button' id='resetBT' class="button_an_clean" style="margin-left: 1em; background-repeat: repeat-x;" value='选择所有列' onclick="$(':checkbox[name=colsattr]').attr('checked',true);" />
						<input type='button' id='resetBT' class="button_an_clean" style="margin-left: 1em; background-repeat: repeat-x;" value='取消所有选择列' onclick="$(':checkbox[name=colsattr]').attr('checked',false);" />
					</td>
				</tr>

			</table>
			<table width="100%">
				<tr>
					<td id="show_headers">&nbsp;</td>
				</tr>
			</table>
		</div>
	</div>
	<div class="clear_h10"></div>
	<div>
		<div id='TopBarMnt'></div>
		<table id='dataGrid'></table>
		<div id='dataBar'></div>
	</div>
	<script type="text/javascript">
		var irisGrid = new IrisGrid("dataGrid", "dataBar", 'TopBarMnt');
		var prcWin = new progressWin("${res}");//初始化遮罩层
		var grant_code = $("#grant_code").val();//获取首次的值
		function closeDialog() {
			tb_remove();
		}

		var i = 0;
		jQuery(function() {
			//定时查看项目类别是否改变
			window.setInterval(function(){
				if(grant_code != $("#grant_code").val()){
					//判断项目类别是不是已清空
					if($("#grant_code").val() != ''){
						$.ajax({
							url:'${ctx}/prpapprove/show_headers?grantCode='+$("#grant_code").val(),
							type:'get',
							success:function(data){
								$("#show_headers").html(data);
							},
							error:function(data){
								alert("出错了");
							}
						});							
					}else{
						$("#show_headers").html("");
					}
					grant_code = $("#grant_code").val();
				}
			},500);
			
			$("#searchBt").click(function(){
				//先封装数据
				var searchString = getParams();
				var colnames = getColName();
				if(colnames != ''){
					$("#dataGrid").jqGrid('GridUnload',null);
					$("#TopBarMnt").html("");
					irisGrid = new IrisGrid("dataGrid", "dataBar", 'TopBarMnt');
					columnAttrList = setColAttr();
					
//	 				var formats = 	getColFormat();				
					irisGrid.setColumnAttrs(columnAttrList);
					///alert(12122121);
					irisGrid.setUrl("${ctx}/prpapprove/list-grid?searchString="+encodeURIComponent(searchString)+"&cols="+encodeURIComponent(colnames));//查询url
					irisGrid.setCaption("暂写");
					irisGrid.setDefaultSortName("AA");//默认排序字段
					irisGrid.setDefaultSortorder("");
					irisGrid.setWidth(978);//整个表格宽度
					irisGrid.setCheckAble(false);//表格左边是否要复选框
					irisGrid.setShowRowIndex(true);//是否显示行号
//	 				irisGrid.setQueryBox('searchBt', '<c:choose><c:when test="${role == 'chushi'}">prpApprove_search2_chushi</c:when><c:when test="${role == 'shouli'}">prpApprove_search2_shouli</c:when><c:otherwise>prpApprove_search2</c:otherwise></c:choose>');//查询条件 按钮名，查询条件function_key
					irisGrid.build();							
				}else{
					if($("#grant_code").val() == ''){
						alert("请选择项目类别");
					}else{
						alert("请选择列名");
					}
				}
			});
			
		});
		/** 表格初始化**/

		function setColAttr() {
			var columnAttrList = new Array();
			$(":checkbox[name='colsattr']:checked").each(
					function() {
						//alert($(this).val());
						var attrs = $(this).val().split(",");
						if(attrs[1].indexOf('_CLOB') == -1){
							var columnAttr = new ColumnAttr(attrs[0], attrs[1],attrs[1], 1, "center", true);
							columnAttrList.push(columnAttr);
						}else{
							var columnAttr = new ColumnAttr(attrs[0], attrs[1],attrs[1], 3, "center", true);
							columnAttrList.push(columnAttr);							
						}
					});
			return columnAttrList;
		}
		
		function getColName() {
			var columnAttrList = new Array();
			$(":checkbox[name='colsattr']:checked").each(function() {
				var attrs = $(this).val().split(",");
				columnAttrList.push(attrs[1]);
			});
			return columnAttrList.join(",");
		}
		
		function getColFormat() {
			var columnAttrList = new Array();
			$(":checkbox[name='colsattr']:checked").each(function() {
				//alert($(this).val());

				var attrs = $(this).val().split(",");
				var format = 'text';
				if (attrs.length > 7)
					format = attrs[7];
				columnAttrList.push(format);
			});
			return columnAttrList.join(",");
		}

		function cleanQueryBox() {
			$("[id^='_dyn_criteria'][id$='_c']", "#prpApprove_search4org")
					.each(function() {
						$(this).children().each(function() {
							$(this).val('');
						});
					});
		}
		
		function getParams(){
			//先封装数据
			var urlStr = "";
			var criteria_key = $("#_dyn_panel").attr("functionkey");
			var queryTableObj = $("#" + criteria_key + " *[id='_dyn_panel']");
			var querySels = [];
			$("[id^='_dyn_criteria'][id$='_field']", queryTableObj).each(
					function() {
						querySels.push($(this).attr('id'));
					});
			var querySelIdCrowd = querySels;
			
			var queryKVStr = '';
			for ( var i = 0; i < querySelIdCrowd.length; i++) {
				var selId = querySelIdCrowd[i];
				var queryId = $("#"+criteria_key).find('#' + selId).val();
				var destContral = $("#"+criteria_key).find('#' + queryId, $('#' + selId).parent().next());
				var queryValue = destContral.val();
				var fieldname = destContral.attr("name");
				var queryCellValue = $.trim(queryValue);
				if(i != querySelIdCrowd.length-1){
					urlStr = urlStr +fieldname+":"+queryCellValue+"[tear]";
				}else{
					urlStr = urlStr +fieldname+":"+queryCellValue;
				}
			}
			return urlStr;
		}
		function initOnlyChooseLeaf(params, treeNode) {
			
			scmWarn("请选择具体的项目类别");
			$("#scmtip_container").css("z-index", '999999999');
				return false;
	}
		
	</script>
</body>
</html>